package cn.edu.ldu.modules.controller;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import cn.edu.ldu.http.rqtUtils;
import cn.edu.ldu.modules.entity.ChatHistoryEntity;
import cn.edu.ldu.util.Consts;

public class ChatHistoryController extends BaseController {

    public static List<ChatHistoryEntity> getHistoryByUserId(Long userId, Long targetId, String token) throws Exception {
        StringBuffer sb = new StringBuffer();
        sb.append(Consts.getChatHistoryByUserId).append("/").append(userId).append("?targetId=").append(targetId);

        JSONObject jsonObject = rqtUtils.httpclientGet(sb, token);

        if(jsonObject.getString("msg").equals("success")){
            return JSONObject.parseArray(jsonObject.getString("list"), ChatHistoryEntity.class);
        }
        return null;

    }

    public static List<ChatHistoryEntity> getWithoutHandleMsg(Long userId, Integer status, String token) throws Exception{
        StringBuffer sb = new StringBuffer();
        sb.append(Consts.getWithoutHandleMSG_CHAT).append("/").append(userId).append("?status=").append(status);
        JSONObject jsonObject = rqtUtils.httpclientGet(sb, token);
        if(jsonObject.getString("msg").equals("success")){
            return JSONObject.parseArray(jsonObject.getString("list"), ChatHistoryEntity.class);
        }
        return null;

    }


    public static void addChatHistory(ChatHistoryEntity chatHistoryEntity, String token) throws Exception{
        String jsonString = JSONObject.toJSONString(chatHistoryEntity);

        String responseResult = rqtUtils.httpclientPost(new StringBuffer(Consts.addChatHistory), jsonString, token);
    }

}
